## Universidade Federal do Rio Grande do Sul - Instituto de Informatica
## Departamento de Informatica Teorica
## Modelos de Linguagem de Programacao - 2013/1
## Professor: Lucas Schnorr
## Alunos: Felipe Schimidt e Mario Gasparoni Junior
##
##
## 
## Implementacao do modulo 'shooter' seguindo recomendacoes em:
## http://www.pygame.org/docs/

import pygame, commons, sys, ammo
#ammunition = ammo.Ammo() #TODO:REMOVE ?
#fired_spoons = []
class Shooter:	
	'Definitions of the Shooter'	
	
	START_X_POS = 320
	START_Y_POS = 110
	X_POS = 0
	Y_POS = 0
	spoon_launcher = pygame.image.load("images/spoon_launcher.png")
	shoot_effect = pygame.image.load("images/shoot.png")

	shoot_delay = commons.SHOOT_DELAY
	shooted = False

	
	def __init__(self):
		self.X_POS = self.START_X_POS
		self.Y_POS = self.START_Y_POS
	
	def track(self, screen):		
		pressed = pygame.key.get_pressed()
		if pressed[pygame.K_RIGHT] or pressed[pygame.K_d]:
			#We must consider the shooter size, thats why we subtract 75
			if self.X_POS <= commons.MAX_HEIGHT - 75:
					self.X_POS += commons.PLAYER_LEVEL
		if pressed[pygame.K_LEFT] or pressed[pygame.K_a]:
			if self.X_POS >= 0:
				self.X_POS -= commons.PLAYER_LEVEL
		if pressed[pygame.K_SPACE]:
			self.shooted = True
#			fired_spoons.append(ammo.Ammo(self.center_x(), self.center_y()))

		screen.blit(self.spoon_launcher, [self.X_POS,self.Y_POS])
		self.shoot(screen)
#		ammunition.update(screen, fired_spoons)
#		pygame.draw.rect(screen, color, pygame.Rect(X_POS, Y_POS, 30, 30)) 	

	def center_x(self):
		return self.X_POS + 31

	def center_y(self):
		return self.Y_POS + 39

	def shoot(self, screen):
		self.center_x()
		if self.shooted:
			if (self.shoot_delay > 0):

				#This coordinates makes the effect of shooting in the middle of the shooter
				screen.blit(self.shoot_effect, [self.center_x(),self.center_y()])
				self.shoot_delay -= 1
			else:
				self.shoot_delay = commons.SHOOT_DELAY
				self.shooted = False

